package cn.aopmin.handler;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一返回结果
 * @author liuxm34
 * @since 2025/3/15
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class R<T> {
    private int status;
    private String message;
    private T data;


    public static <T> R<T> success(T data) {
        return R.<T>builder()
                .status(200)
                .message("success")
                .data(data)
                .build();
    }


    public static <T> R<T> success(int status, T data) {
        return R.<T>builder()
                .status(status)
                .message("success")
                .data(data)
                .build();
    }

    public static <T> R<T> success(String message) {
        return R.<T>builder()
                .status(200)
                .message(message)
                .build();
    }

    public static <T> R<T> success(String message, T data) {
        return R.<T>builder()
                .status(200)
                .message(message)
                .data(data)
                .build();
    }

    public static <T> R<T> success(int status, String message, T data) {
        return R.<T>builder()
                .status(status)
                .message(message)
                .data(data)
                .build();
    }

    public static <T> R<T> success() {
        return R.<T>builder()
                .status(200)
                .message("success")
                .data(null)
                .build();
    }

    public static <T> R<T> error(int status, String message) {
        return R.<T>builder()
                .status(status)
                .message(message)
                .build();
    }
    public static <T> R<T> error(String message) {
        return R.<T>builder()
                .status(500)
                .message(message)
                .build();
    }

    public static <T> R<T> error() {
        return R.<T>builder()
                .status(500)
                .message("系统异常")
                .data(null)
                .build();
    }
}